package com.ruoyi.system.service.impl;

import java.util.List;

import com.ruoyi.system.domain.Complaint;
import com.ruoyi.system.mapper.ComplaintMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.BusinessinfoMapper;
import com.ruoyi.system.domain.Businessinfo;
import com.ruoyi.system.service.IBusinessinfoService;
import com.ruoyi.common.support.Convert;

/**
 * 商家 服务层实现
 * 
 * @author ruoyi
 * @date 2019-07-16
 */
@Service
public class BusinessinfoServiceImpl implements IBusinessinfoService 
{
	@Autowired
	private BusinessinfoMapper businessinfoMapper;
	@Autowired
	private ComplaintMapper complaintMapper;

	/**
     * 查询商家信息
     * 
     * @param businessinfoId 商家ID
     * @return 商家信息
     */
    @Override
	public Businessinfo selectBusinessinfoById(Integer businessinfoId)
	{
	    return businessinfoMapper.selectBusinessinfoById(businessinfoId);
	}
	
	/**
     * 查询商家列表
     * 
     * @param businessinfo 商家信息
     * @return 商家集合
     */
	@Override
	public List<Businessinfo> selectBusinessinfoList(Businessinfo businessinfo)
	{
	    return businessinfoMapper.selectBusinessinfoList(businessinfo);
	}
	/**
	 * 无条件查询商家列表
	 *
	 * @param businessinfo 商家信息
	 * @return 商家集合
	 */
	@Override
	public List<Businessinfo> selectBusinessinfoList2(Businessinfo businessinfo)
	{
		return businessinfoMapper.selectBusinessinfoList2(businessinfo);
	}
    /**
     * 新增商家
     * 
     * @param businessinfo 商家信息
     * @return 结果
     */
	@Override
	public int insertBusinessinfo(Businessinfo businessinfo)
	{
	    return businessinfoMapper.insertBusinessinfo(businessinfo);
	}
	
	/**
     * 修改商家
     * 
     * @param businessinfo 商家信息
     * @return 结果
     */
	@Override
	public int updateBusinessinfo(Businessinfo businessinfo)
	{
	    return businessinfoMapper.updateBusinessinfo(businessinfo);
	}

	/**
     * 删除商家对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
	@Override
	public int deleteBusinessinfoByIds(String ids)
	{
		return businessinfoMapper.deleteBusinessinfoByIds(Convert.toStrArray(ids));
	}

	/**
	 * 商户状态修改
	 * @param businessinfo 商户信息
	 * @return 结果
	 */
	@Override
	public int changeStatus(Businessinfo businessinfo) {
		return businessinfoMapper.updateBusinessinfo(businessinfo);
	}

	@Override
	public List<Businessinfo> selectBusinessinfoByComlaintId(Integer complaintId) {
		Complaint complaint = complaintMapper.selectComplaintById(complaintId);
		List<Businessinfo> businessinfos = businessinfoMapper.selectBusinessinfoList2(null);
		for (Businessinfo businessinfo:businessinfos){
			if(businessinfo.getBusinessinfoId()== complaint.getComplaintId()){
				businessinfo.setFlag(true);
			}
		}
		return businessinfos;
	}

}
